using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    const double RANGE = 69.170833333333333333333;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] != null)
        {
            txtScale.Text = ((User)Session["user"]).Range.ToString();
            TextBox1.Text = ((User)Session["user"]).UserName;
            TextBox2.Text = ((User)Session["user"]).ZipCode;
        }
    }

    protected void btnGo_Click(object sender, EventArgs e)
    {
        GridPool upool = (GridPool)Application["UserPool"];
        if (upool == null)
            upool = CreateUserPool();
        //User u = new User(
        //            (string)(Session["username"] = TextBox1.Text),
        //            (string)(Session["zip"] = TextBox2.Text),
        //            (int)(Session["scale"] = int.Parse(txtScale.Text))
        //            );
        User u = new User(
                    TextBox1.Text, TextBox2.Text, int.Parse(txtScale.Text));

        Session["user"] = u;
        upool.Add(u);

        lblInfo.Text = "Longitude:" + u.Location.Longitude
        + "<BR>Latitude:" + u.Location.Latitude;
        lblInfo.Text += "<BR># of registered users: " + upool.Count;

        Response.Redirect(@"./chat.aspx");
    }

    GridPool CreateUserPool()
    {
        Application["UserPool"] = new GridPool();
        return (GridPool)Application["UserPool"];
    }

    protected void btnLogOut_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        TextBox1.Text = TextBox2.Text = null;
    }
}
